//
//  DeepestViewController.m
//  much
//
//  Created by weijunjie on 2018/12/29.
//  Copyright © 2018年 iOS. All rights reserved.
//

#import "DeepestViewController.h"
#import "EasyNavigation.h"
#import "RDVTabBarController.h"
#import "UserLoginViewController.h"

static id UserAgainLoginNotifyHandler = nil;

@interface DeepestViewController ()

@end

@implementation DeepestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationView.titleLabel.font = APPFONT(17);
    self.view.backgroundColor = [UIColor whiteColor];
    [self _reLayout];
    
    UserAgainLoginNotifyHandler = [NOTIFY_HANDLE addObserverForName:UserLogoutNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
        [self checkUserLogin];
    }];
}
- (instancetype)initWithNib {
    if (self = [super initWithNibName:NSStringFromClass([self class]) bundle:nil]) {
    }
    return self;
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if ([self isKindOfClass:NSClassFromString(@"MallHomeViewController")] ||
        [self isKindOfClass:NSClassFromString(@"CategoryHomeViewController")] ||
        [self isKindOfClass:NSClassFromString(@"ReadHomeViewController")] ||
        [self isKindOfClass:NSClassFromString(@"CartHomeViewController")] ||
        [self isKindOfClass:NSClassFromString(@"UserCenterHomeViewController")]
        ) {
        [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
    }
}
- (void)viewWillDisappear:(BOOL)animated {
    [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
    [super viewWillDisappear:animated];
}
- (void)_reLayout {}

- (void)checkUserLogin {
    dispatch_queue_t loginQueue = dispatch_queue_create("loginQueue.much.com", DISPATCH_QUEUE_CONCURRENT);
    dispatch_sync(loginQueue, ^{
        [self.navigationController popToRootViewControllerAnimated:YES];
    });
    dispatch_sync(loginQueue, ^{
        UserLoginViewController *vc = [[UserLoginViewController alloc] init];
        [self.navigationController presentViewController:vc animated:YES completion:nil];
    });
}

- (void)setTitle:(NSString *)title {
    [super setTitle:title];
    [self.navigationView setTitle:title];
}

- (void)dealloc {
    if (UserAgainLoginNotifyHandler) {
        [NOTIFY_HANDLE removeObserver:UserAgainLoginNotifyHandler];
        UserAgainLoginNotifyHandler = nil;
    }
}

@end
